package com.abe.jetpack.base

import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProvider
import android.arch.lifecycle.ViewModelProviders
import com.abe.libcore.base.screen.AbeActivity

abstract class AutoBaseActivity : AbeActivity() {
    override fun isAutoZoom(): Boolean {
        return true
    }

    val factory: ViewModelProvider.Factory by lazy {
        if (application is ManagerAPP) {
            val mainApplication = application as ManagerAPP
            return@lazy mainApplication.factory
        } else {
            throw IllegalStateException("application is not AbeApp")
        }
    }

    protected inline fun <reified T : ViewModel> getInjectViewModel() = ViewModelProviders.of(this, factory).get(T::class.java)
}